export interface EventProp{
    [propName:string]:any
}
class EventBus{
    events: EventProp;
    constructor(){
        this.events = {};
    }

    $on(eventName:string,callback:any){
        if(!this.events[eventName]){
            this.events[eventName] = [];
        }

        this.events[eventName].push(callback);
        
    }

    $emit(eventName:string,...params:any[]){
        this.events[eventName].forEach((fun:any) => {
            fun(...params);
        })
    }
}

// 订阅事件  $on('事件名',(参数) => {})  发布事件：$emit('事件名',参数)

// this.events = {
//     "fun":[callback1,callback2]
// }

export default new EventBus();

